package com.graduation_design.modules.search.config;

import com.graduation_design.modules.search.service.AppSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class SearchContextStartup implements ApplicationRunner {
    // 在项目启动的时候就会调用这个类的run方法,自动同步一遍es的数据

    @Resource
    AppSearchService appSearchService;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        int count = appSearchService.initEsData();
        log.info("ok，已初始化搜索数据{}条", count);
    }
}
